package org.httpclient.spring.boot.autoconfigure;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * HttpClient连接池配置
 * 
 * @author chenfanglin
 * @date: 2018年8月15日 下午7:22:35
 */
@ConfigurationProperties(prefix = HttpClientPoolProperties.HTTP_CLIENT_POOL_PREFIX)
public class HttpClientPoolProperties {

	public static final String HTTP_CLIENT_POOL_PREFIX = "spring.httpclient.pool";

	/**
	 * 连接池总连接数。默认：50个
	 */
	private Integer maxTotal = 50;

	/**
	 * 设置每个主机地址的连接数。默认等于maxTotal
	 */
	private Integer defaultMaxPerRoute = maxTotal;

	/**
	 * 连接上服务器(握手成功)的时间，超出该时间抛出connect timeout
	 */
	private Integer connectTimeout = 2000;

	/**
	 * 从连接池中获取连接的超时时间，超过该时间未拿到可用连接，会抛出org.apache.http.conn.ConnectionPoolTimeoutException:
	 * Timeout waiting for connection from pool
	 */
	private Integer connectionRequestTimeout = 500;

	/**
	 * 服务器返回数据(response)的时间，超过该时间抛出read timeout
	 */
	private Integer socketTimeout = 3000;

	/**
	 * 在连接池中最大的空闲时间(用于定期清理空闲连接),默认5分钟,单位：豪秒(ms)
	 */
	private Long maxIdleTimeMs = 300000L;

	public Integer getMaxTotal() {
		return maxTotal;
	}

	public void setMaxTotal(Integer maxTotal) {
		this.maxTotal = maxTotal;
	}

	public Integer getDefaultMaxPerRoute() {
		return defaultMaxPerRoute;
	}

	public void setDefaultMaxPerRoute(Integer defaultMaxPerRoute) {
		this.defaultMaxPerRoute = defaultMaxPerRoute;
	}

	public Integer getConnectTimeout() {
		return connectTimeout;
	}

	public void setConnectTimeout(Integer connectTimeout) {
		this.connectTimeout = connectTimeout;
	}

	public Integer getConnectionRequestTimeout() {
		return connectionRequestTimeout;
	}

	public void setConnectionRequestTimeout(Integer connectionRequestTimeout) {
		this.connectionRequestTimeout = connectionRequestTimeout;
	}

	public Integer getSocketTimeout() {
		return socketTimeout;
	}

	public void setSocketTimeout(Integer socketTimeout) {
		this.socketTimeout = socketTimeout;
	}

	public Long getMaxIdleTimeMs() {
		return maxIdleTimeMs;
	}

	public void setMaxIdleTimeMs(Long maxIdleTimeMs) {
		this.maxIdleTimeMs = maxIdleTimeMs;
	}

}
